// 不同模型的data:处理方法的映射

import e from "express";
import { ModelsType } from "../dto/create-chat.dto";
const modelResponseEndTag = ['[DONE]', 'end', 'data: {}']

// ernieLite8k 响应模型内容处理
const handleErnieLite8kData = (dataLine: string) => {
    const dataPart = dataLine.replaceAll('data: ', '')
    const findEndTag = modelResponseEndTag.find(el => dataPart.indexOf(el) > -1) && dataPart
    if (findEndTag) {
        return ''
    } else {
        const data = JSON.parse(dataPart)
        return data.choices[0].delta.content
    }
}

// modelResponseEndTag 模型响应结束的标志
export const modelDataDealMethodsMap: Record<ModelsType, Function> = {
    'ernie-lite-8k': handleErnieLite8kData,
    "deep-seek-r1": handleErnieLite8kData
}